\documentclass[a4paper]{article}
\usepackage[affil-it]{authblk}
%\usepackage[backend=bibtex,style=numeric]{biblatex}
%\usepackage{amsmath}
\usepackage{ctex}
\usepackage{listings}

\usepackage{geometry}
\geometry{margin=1.5cm, vmargin={0pt,1cm}}
\setlength{\topmargin}{-1cm}
\setlength{\paperheight}{29.7cm}
\setlength{\textheight}{25.3cm}

%\addbibresource{citation.bib}

\begin{document}
% =================================================
\title{Report \# 1}

\author{YijunXu 3220101901
  \thanks{Electronic address: \texttt{3220101901@zju.deu.cn}}}
\affil{(qiangji2201), Zhejiang University }


\date{Due time: 10.7}

\maketitle

%\begin{abstract}
%   The abstract is not necessary for the theoretical homework, 
%  but for the programming project, 
% you are encouraged to write one.      

%\end{abstract}





% ============================================
\section*{A.}

\subsection{I.}
\begin{lstlisting}[language=C++, caption=Function class]  
class Function {
public:
    virtual double operator() (double x) const = 0;
    virtual double derivative(double x) const {
        /* Type your code here. */
        return 0;   // undefined derivation just return 0
    }
};
\end{lstlisting}    
给出了函数的抽象虚类，继承的函数方便计算函数值和导数值。

\subsection{II.}
\begin{lstlisting}[language=C++, caption=EquationSolver class]
    class EquationSolver{
protected:
    const Function & F;
public:
    EquationSolver(const Function& F) : F(F) {}
    virtual double solve() = 0;
};
\end{lstlisting}
创建一个通用的方程求解器接口。通过将`Function`类的实例传递给`EquationSolver`的构造函数，我们可以在派生类中使用这个函数来解各种类型的方程。不同的方程求解算法可以通过继承`EquationSolver`类并实现`solve()`函数来实现。

% =========================================
\section*{B.}

\begin{verbatim}
  ./programB 
Solving x^{-1} - \tan x on [0, \pi/2]
A root is: 0.860333
Solving x^{-1} - 2^x on [0, 1]
A root is: 0.641186
Solving 2^-x + exp(x) + 2*cos(x) -6 = 0 on [1, 3]
A root is: 1.82938
Solving (x^3 + 4*x^2 + 3*x + 5)/(2*x^3 - 9*x^2 + 18*x -2) on [0, 4]
A root is: 0.117877
\end{verbatim}
经过测试可得是近似根，并且精度符合输入

% ============================================
\section*{C.}

\begin{verbatim}
    ./programC  
Solving x = \tan x near 4.5
A root is: 4.49341
Solving x = \tan x near 7.7
A root is: 7.72525

\end{verbatim}

% ============================================
\section*{D.}

\begin{verbatim}
    ./programD
Solving \sin (x/2) - 1 with initial x0 = 0and x1 = 1.5708
A root is: 3.14052
Solving \sin (x/2) - 1 with initial x0 = 0and x1 = 1
A root is: 3.14034
Solving exp(x) - \tan x with initial x0 = 1and x1 = 1.4
A root is: 1.30633
Solving exp(x) - \tan x with initial x0 = 0and x1 = 1
A root is: -6.28131
Solving x^3 - 12*x^2 + 3*x + 1 with initial x0 = 0and x1 = -0.5
A root is: -0.188685
Solving x^3 - 12*x^2 + 3*x + 1 with initial x0 = 0and x1 = 1
A root is: 0.451543
\end{verbatim} 
在初值不同的情况下可能得到差距很大的根，甚至有可能式子不收敛

% ============================================
\section*{E.}
\begin{verbatim}
    ./programE
solve by bisectionfrom [0,1]
the root is 0.166165
solve by newton near 0.9
the root is 0.166318
solve by secant with initial0.9 and 0.1
the root is 0.166235

\end{verbatim}
对NewtonMethod和SecantMethod尝试不同迭代次数上限，发现迭代次数越多根越接近真实解.

% ============================================
\section*{F.}

\begin{verbatim}
    ./programF
solution for (a): 
the root is 32.9723
solution for (b): 
the root is 33.1684
solution for (c) with initial 0 and 10
the root is -11.5
solution for (c) with initial 100 and 150
the root is 147.028
solution for (c) with initial 5 and 10
the root is -11.5

\end{verbatim}
割线法中初始值的选择非常关键。如果初始值距离实际根太远，由于割线在该区域逼近函数的不足，该方法可能无法收敛，或者收敛到不同的根。

% ===============================================
%\section*{ \center{\normalsize {Acknowledgement}} }
%[1]张平文, and 李铁军. 数值分析——北京大学数学教学系列丛书. 北京大学出版社, 2007.


%\printbibliography

%If you are not familiar with \texttt{bibtex}, 
%it is acceptable to put a table here for your references.
\end{document}
